'''
Python连接数据库创建连接对象
'''
# 1. 导入pymysql
from pymysql import Connection

conn = None
try:
    # 2. 创建连接对象
    conn = Connection(
        host="localhost",  # MySQL数据库IP地址
        port=3306,  # MySQL数据库端口号
        user="root",
        password="root",
        database="db01"
    )

    print(type(conn), conn)
    print(conn.get_host_info())
    print(conn.get_server_info())
except Exception as e:
    print("异常：",e)
finally:
    # 3. 释放资源
    if conn:
        conn.close()



